package com.bandaotixi.cashier.api.system.service;

import com.bandaotixi.cashier.api.system.mapper.DictMapper;
import com.bandaotixi.cashier.api.system.model.entity.Dict;
import com.bandaotixi.cashier.api.system.model.entity.DictItem;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class DictService extends MPJBaseServiceImpl<DictMapper, Dict> {
    private final DictItemService dictItemService;
    public void deleteDictByIds(List<String> ids) {
        for (String id : ids) {
            Dict dict = this.getById(id);
            if (dict != null) {
                boolean removeResult = this.removeById(id);
                // 删除字典下的字典项
                if (removeResult) {
                    dictItemService.remove(
                            new LambdaQueryWrapper<DictItem>()
                                    .eq(DictItem::getDictCode, dict.getDictCode())
                    );
                }

            }
        }
    }
}




